package glt.com.excel_handler;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.imageio.ImageIO;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class DataHandler implements Runnable{
	private MainWin mainWin; 
	public DataHandler(MainWin main) {
		this.mainWin = main;
	}
	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		try {
			MainWin mainWin=null;
			DataHandler handler = new DataHandler(mainWin);
			Map<String, String> map = new HashMap<>();
//			map.put("堆6簇3_volt", "12,4");
//			//map.put("堆6簇3_volt_range", "289,300");
//			map.put("堆6簇3_temp", "3,4:4,5");
			// map.put("堆6簇3_temp_range", "74,82");
//			
//			map.put("堆9簇5_volt", "11,4");
//			map.put("堆9簇5_volt_range", "37,48");
//			map.put("堆9簇5_temp", "3,4:4,5");
//			map.put("堆9簇5_temp_range", "10,18");
//			
			String str = "301,302";
			String[] arr = str.split(":");

			map.put("堆6簇3_volt", "5,4");
			map.put("堆6簇3_volt_range", "301,312");
			map.put("堆6簇3_temp", "6,4");
			map.put("堆6簇3_temp_range", "74,82");
//			
//			map.put("堆10簇4_volt", "8,4");
//			map.put("堆10簇4_volt_range", "289,300");
//			map.put("堆10簇4_temp", "3,4:4,5");
//			map.put("堆10簇4_temp_range", "73,81");

//			map.put("堆6簇3_volt", "12,4");
//			map.put("堆11簇5_volt_range", "433,444"); // 这表示电芯范围 433-444
//			map.put("堆11簇5_temp", "3,4:4,5");       // 温度要拷贝两列，用 : 分隔
//			map.put("堆11簇5_temp_range", "109,117");

//			handler.handleFile(map);
//			handler.handleChart(map);

//			handler.addNewCol("C:\\home\\data\\堆11簇5\\10月\\10月温度.xlsx", 3, "C:\\home\\data\\堆11簇5\\10月\\10月温度极值.xlsx", 4);
//			handler.addNewCol("C:\\home\\data\\堆11簇5\\10月\\10月温度.xlsx", 4, "C:\\home\\data\\堆11簇5\\10月\\10月温度极值.xlsx", 5);
//			handler.addNewCol("C:\\home\\data\\堆11簇5\\10月\\10月电压.xlsx", 12, "C:\\home\\data\\堆11簇5\\10月\\10月电压极值.xlsx", 4);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void handleFile(MainWin mainWin) throws NumberFormatException, FileNotFoundException, IOException {
		// File root = new File(PublicConstant.rootPath); //底目录（所有堆）
		File root = new File(mainWin.textSourcePath.getText());

		File[] monthList = root.listFiles(); // 目录列表
		// String clusterName = "";

		for (File month : monthList) { // 遍历月份
			if (month.isDirectory()) {
				File[] xlsxList = month.listFiles();
				for (File xlsx : xlsxList) { // 遍历单个文件
					// 电压文件的处理
					if (xlsx.getName().contains("电压.") && !xlsx.getName().contains("~$")) {
						String sourceFileName = xlsx.getAbsolutePath();
						System.out.println("sourceFileName=" + sourceFileName);
						String[] tmp = sourceFileName.split("\\.");
						String destFileName = tmp[0] + "极值.xlsx";
						System.out.println("destFileName=" + destFileName);
						String[] voltColStr = mainWin.textVoltCol.getText().split(",");
						String[] voltExtremColStr = mainWin.textVoltExtremCol.getText().split(",");

						for (int i = 0; i < voltColStr.length; i++) {
							mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "开始处理" + destFileName);
							addNewCol(sourceFileName, Integer.parseInt(voltColStr[i]), destFileName,
									Integer.parseInt(voltExtremColStr[i]));
							mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + destFileName + "  处理完成...");
						}

					}

					// 温度文件的处理
					if (xlsx.getName().contains("温度.") && !xlsx.getName().contains("~$")
							&& !xlsx.getName().contains("lock")) {
						String sourceFileName = xlsx.getAbsolutePath();
						System.out.println("sourceFileName=" + sourceFileName);
						String[] tmp = sourceFileName.split("\\.");
						String destFileName = tmp[0] + "极值.xlsx";
						System.out.println("destFileName=" + destFileName);
						String[] tempColStr = mainWin.textTempCol.getText().split(",");
						String[] tempExtremColStr = mainWin.textTempExtremCol.getText().split(",");

						for (int i = 0; i < tempColStr.length; i++) {
							mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "开始处理" + destFileName);
							addNewCol(sourceFileName, Integer.parseInt(tempColStr[i]), destFileName,
									Integer.parseInt(tempExtremColStr[i]));
							mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + destFileName + "  处理完成...");
						}
					}
				}
			}
		}
		mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "完成复制列操作...");

	}

	/**
	 * 生成图表
	 */
	@Override
	public void run(){
	//public void handleChart(MainWin mainWin) throws FileNotFoundException, IOException {
		File root = new File(mainWin.textSourcePath.getText()); // 底目录（所有堆）
		String[] pathArr = mainWin.textSourcePath.getText().split(File.separator);
		mainWin.textArea.setText("开始生成...");
		mainWin.btnGen.setEnabled(false);
		String clusterName = pathArr[pathArr.length-1];
		String monthName = "";
		File[] monthList = root.listFiles();
		
		for (File month : monthList) { // 遍历月份
			monthName = month.getName();
			if (month.isDirectory()) {
				File[] xlsxList = month.listFiles();
				for (File xlsx : xlsxList) { // 遍历单个文件
					if (!xlsx.getName().contains("~$")) {
						String absPath = xlsx.getAbsolutePath();
						try {
							if (xlsx.getName().contains("温度极值")) {
								doHandleTempExtrem(mainWin, clusterName, monthName, absPath);
							} else if (xlsx.getName().contains("温度")) {
								doHandleTemp(mainWin, clusterName, monthName, absPath);
							} else if (xlsx.getName().contains("电压极值")) {
								doHandleVoltExtrem(mainWin, clusterName, monthName, absPath);
							} else if (xlsx.getName().contains("电压")) {
								doHandleVolt(mainWin, clusterName, monthName, absPath);
							}
						}catch(Exception e) {
							
						}
					}
				}
			}
		}
		
		mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "已生成所有图片...");
		mainWin.btnGen.setEnabled(true);
	}

	/**
	 * 解析温度数据
	 * 
	 * @param map
	 * @param clusterName 堆几簇几
	 * @param month       几月
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	public void doHandleTemp(MainWin mainWin, String clusterName, String monthName, String absPath)
			throws FileNotFoundException, IOException {
		// 1、获取数据集
		List<Double> rangeData = new ArrayList<>();
		XYSeriesCollection dataset = handleXYSeriesData(absPath, rangeData);
		Double min = rangeData.get(0);
		Double max = rangeData.get(1);

		// 2、拼接文件名
		// 电芯范围
		//String ranges = map.get(clusterName + "_temp_range");
		String ranges = mainWin.textTempRange.getText();
		String[] range = ranges.split(",");
		// 拼接chart名称
		String picTitle = MessageFormat.format(mainWin.textTempPng.getText(), monthName, clusterName, range[0], range[1]);

		// 3、加粗指定线条
//		String mapVal = map.get(clusterName + "_temp");
//		String[] posSet = mapVal.split(":");
//		
//		List<Integer> blodLine = new ArrayList<>();
//		
//		for (String one : posSet) {
//			String[] pos = one.split(",");
//			blodLine.add(Integer.parseInt(pos[0]) - 1);
//		}
		
		List<Integer> blodLine = new ArrayList<>();
		String[] tempCols = mainWin.textTempCol.getText().split(",");
		for (String col : tempCols) {
			blodLine.add(Integer.parseInt(col) - 1);
		}

		// 4、创建JFreeChart对象
		JFreeChart chart = ChartFactory.createXYLineChart(picTitle, // 图标题
				"num", // x轴标题
				"temp", // y轴标题
				dataset, // 数据集
				PlotOrientation.VERTICAL, // 图表方向
				true, true, false);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setRange(min - 0.5, max + 0.5); // 设置Y轴的范围从0到100

		XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

		// 设置第四条下载折线为黑色（下标从0开始）曲线数量超过五条时颜色自动设置少于五个安顺序配置颜色
		renderer.setSeriesPaint(0, Color.cyan);
		renderer.setSeriesPaint(1, Color.yellow);
		renderer.setSeriesPaint(2, Color.blue);
		System.out.println("blodLine = " + blodLine.toString());
		renderer.setSeriesPaint(blodLine.get(0), Color.red);
		renderer.setSeriesStroke(blodLine.get(0), new java.awt.BasicStroke(4.0f));
		
		 if (blodLine.size() > 1) { 
		  renderer.setSeriesPaint(blodLine.get(1), Color.green);
		  renderer.setSeriesStroke(blodLine.get(1), new java.awt.BasicStroke(4.0f));
		 }
		// 数据区的表示者(不设置看不到折线)
		plot.setRenderer(renderer);

		// 5、生成文件
		BufferedImage chartImage = chart.createBufferedImage(1920, 1080);
		try {
			ImageIO.write(chartImage, "png", new File(mainWin.textPngPath.getText()+ File.separator + picTitle + ".png"));
			mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "已生成图片:" + picTitle + ".png");
			
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 解析温度极值数据
	 * 
	 * @param month
	 * @param absPath
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	public void doHandleTempExtrem(MainWin mainWin, String clusterName, String monthName, String absPath)
			throws FileNotFoundException, IOException {
		// 1、获取数据集
		List<Double> rangeData = new ArrayList<>();
		XYSeriesCollection dataset = handleXYSeriesData(absPath, rangeData);
		Double min = rangeData.get(0);
		Double max = rangeData.get(1);

		// 2、计算线条要加粗的电芯，以及生成文件名
		// 电芯范围，获取起始电芯
		//String ranges = map.get(clusterName + "_temp_range");
		String ranges = mainWin.textTempRange.getText();
		String[] range = ranges.split(",");
		int beginCell = Integer.parseInt(range[0]);

//		List<String> boldCell = new ArrayList<>();
//
//		String mapVal = map.get(clusterName + "_temp");
//		
//		String[] posSet = mapVal.split(":");
//		
//		List<Integer> blodLine = new ArrayList<>();
//		for (String one : posSet) {
//			String[] pos = one.split(",");
//			blodLine.add(Integer.parseInt(pos[1]) - 1);
//			boldCell.add(String.valueOf(beginCell + Integer.parseInt(pos[0]) - 1));
//		}
		List<Integer> blodLine = new ArrayList<>();
		List<String> boldCell = new ArrayList<>();
		String[] tempExtremCols = mainWin.textTempExtremCol.getText().split(",");
		String[] tempCols = mainWin.textTempCol.getText().split(",");
		for (int i = 0 ;i < tempExtremCols.length ;i++) {
			blodLine.add(Integer.parseInt(tempExtremCols[i]));
			boldCell.add(String.valueOf(beginCell +  ( Integer.parseInt(tempCols[i]) - 1) ) ) ;
		}
		
		
		
		
		

		// 文件名
		String picTitle = MessageFormat.format(mainWin.textTempExtremPng.getText(), monthName, clusterName,
				boldCell.stream().collect(Collectors.joining(",")));

		// 3、创建JFreeChart对象
		JFreeChart chart = ChartFactory.createXYLineChart(picTitle, // 图标题
				"num", // x轴标题
				"temp", // y轴标题
				dataset, // 数据集
				PlotOrientation.VERTICAL, // 图表方向
				true, true, false);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setRange(min - 0.5, max + 0.5); // 设置Y轴的范围从0到100

		XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

		// 设置第四条下载折线为黑色（下标从0开始）曲线数量超过五条时颜色自动设置少于五个安顺序配置颜色
		renderer.setSeriesPaint(0, Color.cyan);
		renderer.setSeriesPaint(1, Color.orange);
		renderer.setSeriesPaint(2, Color.blue);
		
		System.out.println("blodLine = " + blodLine.toString());
		renderer.setSeriesPaint(blodLine.get(0) -1, Color.red);
		renderer.setSeriesStroke(blodLine.get(0) -1 , new java.awt.BasicStroke(4.0f));

		
		 if (blodLine.size() > 1 ) {
			 renderer.setSeriesPaint(blodLine.get(1) -1 ,Color.green); 
			 renderer.setSeriesStroke(blodLine.get(1) -1 , new java.awt.BasicStroke(4.0f));
		 }

		// 数据区的表示者(不设置看不到折线)
		plot.setRenderer(renderer);

		// 4、生成文件
		BufferedImage chartImage = chart.createBufferedImage(1920, 1080);
		try {
			ImageIO.write(chartImage, "png", new File(mainWin.textPngPath.getText() + File.separator + picTitle + ".png"));
			mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "已生成图片:" + picTitle + ".png");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 处理电压数据
	 * 
	 * @param month
	 * @param absPath
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public void doHandleVolt(MainWin mainWin, String clusterName, String monthName, String absPath)
			throws FileNotFoundException, IOException {
		// 1、获取数据集
		List<Double> rangeData = new ArrayList<>();
		XYSeriesCollection dataset = handleXYSeriesData(absPath, rangeData);
		Double min = rangeData.get(0);
		Double max = rangeData.get(1);

		// 2、拼接文件名
		// 电芯范围
		//String ranges = map.get(clusterName + "_volt_range");
		String ranges = mainWin.textVoltRange.getText();
		String[] range = ranges.split(",");
		// 拼接chart名称
		String picTitle = MessageFormat.format(mainWin.textVoltPng.getText(), monthName, clusterName, range[0], range[1]);

		// 3、加粗指定线条
		//String mapVal = map.get(clusterName + "_volt");
		
		String mapVal = mainWin.textVoltCol.getText();
		String[] pos = mapVal.split(",");
		List<Integer> blodLine = new ArrayList<>();
		String[] tempCols = mainWin.textVoltCol.getText().split(",");
		for (String col : tempCols) {
			blodLine.add(Integer.parseInt(col) - 1);
		}
		// 4、创建JFreeChart对象
		JFreeChart chart = ChartFactory.createXYLineChart(picTitle, // 图标题
				"num", // x轴标题
				"volt", // y轴标题
				dataset, // 数据集
				PlotOrientation.VERTICAL, // 图表方向
				true, true, false);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setRange(min - 0.2, max + 0.2); // 设置Y轴的范围从0到100

		XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

		// 设置第四条下载折线为黑色（下标从0开始）曲线数量超过五条时颜色自动设置少于五个安顺序配置颜色
		renderer.setSeriesPaint(0, Color.cyan);
		renderer.setSeriesPaint(1, Color.orange);
		renderer.setSeriesPaint(2, Color.blue);
		renderer.setSeriesPaint(3, Color.green);
		System.out.println("blodLine = " + blodLine);
		renderer.setSeriesPaint(blodLine.get(0), Color.red);
		renderer.setSeriesStroke(blodLine.get(0), new java.awt.BasicStroke(4.0f));
		
		if (blodLine.size() > 1) {
			 renderer.setSeriesPaint(blodLine.get(1), Color.green);
			 renderer.setSeriesStroke(blodLine.get(1), new java.awt.BasicStroke(4.0f));
		}
		// 数据区的表示者(不设置看不到折线)
		plot.setRenderer(renderer);

		BufferedImage chartImage = chart.createBufferedImage(1920, 1080);
		try {
			ImageIO.write(chartImage, "png", new File(mainWin.textPngPath.getText() + File.separator +  picTitle + ".png"));
			mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "已生成图片:" + picTitle + ".png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 处理电压极值数据
	 * 
	 * @param pngName
	 * @param month
	 * @param absPath
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public void doHandleVoltExtrem(MainWin mainWin, String clusterName, String monthName, String absPath)
			throws FileNotFoundException, IOException {
		// 1、获取数据集
		List<Double> rangeData = new ArrayList<>();
		XYSeriesCollection dataset = handleXYSeriesData(absPath, rangeData);
		Double min = rangeData.get(0);
		Double max = rangeData.get(1);

		// 2、计算线条要加粗的电芯，以及生成文件名
		// 电芯范围，获取起始电芯
		//String ranges = map.get(clusterName + "_volt_range");
		String ranges = mainWin.textVoltRange.getText();
		String[] range = ranges.split(",");

		int beginCell = Integer.parseInt(range[0]);

		//String mapVal = map.get(clusterName + "_volt");
		//String mapVal = mainWin.textVoltExtremCol.getText();
		//String[] pos = mapVal.split(",");
		
		
		
		
		//-------------
		
		


		List<Integer> blodLine = new ArrayList<>();
		List<String> boldCell = new ArrayList<>();
		String[] voltExtremCols = mainWin.textVoltExtremCol.getText().split(",");
		String[] voltCols = mainWin.textVoltCol.getText().split(",");
		for (int i = 0 ;i < voltExtremCols.length ;i++) {
			blodLine.add(Integer.parseInt(voltExtremCols[i]));
			boldCell.add(String.valueOf(beginCell +  ( Integer.parseInt(voltCols[i]) - 1) ) ) ;
		}
		//-------------

		// 文件名
		String picTitle = MessageFormat.format(mainWin.textVoltExtremPng.getText() , monthName, clusterName,
				boldCell.stream().collect(Collectors.joining(",")));

		// 3、创建JFreeChart对象
		JFreeChart chart = ChartFactory.createXYLineChart(picTitle, // 图标题
				"num", // x轴标题
				"volt", // y轴标题
				dataset, // 数据集
				PlotOrientation.VERTICAL, // 图表方向
				true, true, false);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setRange(min - 0.5, max + 0.5); // 设置Y轴的范围从0到100

		XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

		// 设置第四条下载折线为黑色（下标从0开始）曲线数量超过五条时颜色自动设置少于五个安顺序配置颜色
		renderer.setSeriesPaint(0, Color.cyan);
		renderer.setSeriesPaint(1, Color.orange);
		renderer.setSeriesPaint(2, Color.blue);
		
		renderer.setSeriesPaint(blodLine.get(0) -1 , Color.red);
		renderer.setSeriesStroke(blodLine.get(0) -1 , new java.awt.BasicStroke(4.0f));
		
		if (blodLine.size() > 1 ) {
			 renderer.setSeriesPaint(blodLine.get(1) -1 ,Color.green); 
			 renderer.setSeriesStroke(blodLine.get(1) -1 , new java.awt.BasicStroke(4.0f));
		}
		
		//renderer.setSeriesPaint(4, Color.green);

		// 数据区的表示者(不设置看不到折线)
		plot.setRenderer(renderer);

		BufferedImage chartImage = chart.createBufferedImage(1920, 1080);
		try {

			ImageIO.write(chartImage, "png", new File(mainWin.textPngPath.getText()+ File.separator + picTitle + ".png"));
			mainWin.textArea.setText(mainWin.textArea.getText() + "\n" + "已生成图片:" + picTitle + ".png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 拷贝数据
	 * 
	 * @param sourcePath
	 * @param sourceColIndex : begin with 0
	 * @param destPath
	 * @param destColIndex:  begin with 0
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	private void addNewCol(String sourcePath, int sourceColIndex, String destPath, int destColIndex)
			throws FileNotFoundException, IOException {
		// 1、创建工作簿
		XSSFWorkbook sourceWorkbook = new XSSFWorkbook(new FileInputStream(sourcePath));

		XSSFWorkbook destWorkbook = new XSSFWorkbook(new FileInputStream(destPath));

		// 2、读取第一个工作表(这里的下标与list一样的，从0开始取，之后的也是如此)
		XSSFSheet sourceSheet = sourceWorkbook.getSheetAt(0);
		XSSFSheet destSheet = destWorkbook.getSheetAt(0);

		// 3、逐行读取指定单元格，并拷贝数据
		for (int rowNum = 0; rowNum <= sourceSheet.getLastRowNum(); rowNum++) {
			XSSFRow sourceRow = sourceSheet.getRow(rowNum);
			XSSFRow destRow = destSheet.getRow(rowNum);

			XSSFCell sourceCell = sourceRow.getCell(sourceColIndex);
			if (sourceCell != null) {
				if (destRow == null) {
					continue;
				}
				XSSFCell destCell = destRow.createCell(destColIndex);
				destCell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
				if (rowNum == 0) {

					destCell.setCellValue(sourceCell.getStringCellValue());
				} else {
					destCell.setCellValue(sourceCell.getNumericCellValue());
				}

				System.out.println("rowNum=====" + rowNum);
			}
		}

		// 4、输出文件
		try (FileOutputStream fileOut = new FileOutputStream(destPath)) {
			destWorkbook.write(fileOut);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 数据处理
	 * 
	 * @param absPath 绝对路径
	 * @param range   用于保存Y轴取值范围
	 * @return 待画图的数据集
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public XYSeriesCollection handleXYSeriesData(String absPath, List<Double> range)
			throws FileNotFoundException, IOException {
		// 1、读取文件
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(absPath));
		System.out.println("xssfWorkbook对象：" + xssfWorkbook);
		// 2、读取第一个工作表，下标为0
		XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
		// 3、读取工作行标题，即第一行
		XSSFRow row = sheet.getRow(0);

		List<XYSeries> seriesList = new ArrayList<>();
		for (int i = 1; i < row.getLastCellNum(); i++) {
			System.out.println("表头名：" + row.getCell(i).getStringCellValue());
			seriesList.add(new XYSeries(row.getCell(i).getStringCellValue()));
		}
		// 4、读取数据，并且找到其中最大最小值，用以确定图表的y轴范围
		double min = 0.0;
		double max = 0.0;

		for (int rowNum = 1; rowNum < sheet.getLastRowNum(); rowNum++) {
			System.out.println("line==" + rowNum);
			row = sheet.getRow(rowNum);
			if (row.getCell(1) == null) {
				break;
			}
			for (int i = 0; i < seriesList.size(); i++) {
				if (row.getCell(i + 1) == null)
					continue;
				double num = row.getCell(i + 1).getNumericCellValue();
				if (rowNum == 1 && i == 0) {
					min = num;
					max = num;
				} else {
					if (min > num) {
						min = num;
					} else if (max < num) {
						max = num;
					}
				}
//				System.out.println("min = " + min + ", max = " + max + ", num = " + num);
				seriesList.get(i).add(rowNum, num);
			}
		}
		range.add(min);
		range.add(max);

		// 5、存入待处理成图表的数据集中
		XYSeriesCollection dataset = new XYSeriesCollection();
		for (int i = 0; i < seriesList.size(); i++) {
			dataset.addSeries(seriesList.get(i));
		}

		return dataset;
	}

	

}
